﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;
 

namespace nadModel.ApproverTimeAndExpense
{
    public partial class TimeAndExpenseEntityProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<TimeAndExpenseEntity> entryList = new List<TimeAndExpenseEntity>();

            TimeAndExpenseEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new TimeAndExpenseEntity();
                    entry.Company = item[TimeAndExpenseEntity.COMPANY].ToString();
                    entry.Employeenum = item[TimeAndExpenseEntity.EMPLOYEENUM].ToString();
                    entry.LaborHedSeq = int.Parse(item[TimeAndExpenseEntity.LABORHEDSEQ].ToString());
                    entry.LaborTypePseudo = item[TimeAndExpenseEntity.LABORTYPEPSEUDO].ToString();
                    entry.JobNum = item[TimeAndExpenseEntity.JOBNUM].ToString();
                    entry.AssemblySeq = int.Parse(item[TimeAndExpenseEntity.ASSEMBLYSEQ].ToString());
                    entry.OprSeq = int.Parse(item[TimeAndExpenseEntity.OPRSEQ].ToString());
                    entry.OpCode = item[TimeAndExpenseEntity.OPCODE].ToString();
                    entry.ResourceGrpID = item[TimeAndExpenseEntity.RESOURCEGRPID].ToString();
                    entry.JCDept = item[TimeAndExpenseEntity.JCDEPT].ToString();
                    entry.ResourceID = item[TimeAndExpenseEntity.RESOURCEID].ToString();
                    entry.ShortChar11 = item[TimeAndExpenseEntity.SHORTCHAR11].ToString();
                    entry.Number22 = decimal.Parse(item[TimeAndExpenseEntity.NUMBER22].ToString());
                    entry.Number23 = decimal.Parse(item[TimeAndExpenseEntity.NUMBER23].ToString());
                    entry.ClockinTime = decimal.Parse(item[TimeAndExpenseEntity.CLOCKINTIME].ToString());
                    entry.ClockOutTime = decimal.Parse(item[TimeAndExpenseEntity.CLOCKOUTTIME].ToString());
                    entry.Number03 = decimal.Parse(item[TimeAndExpenseEntity.NUMBER03].ToString());
                    entry.LaborNote = item[TimeAndExpenseEntity.LABORNOTE].ToString();
                    entry.LaborQty = decimal.Parse(item[TimeAndExpenseEntity.LABORQTY].ToString());
                    entry.ScrapQty = decimal.Parse(item[TimeAndExpenseEntity.SCRAPQTY].ToString());
                    entry.ScrapReasonCode = item[TimeAndExpenseEntity.SCRAPREASONCODE].ToString();
                    entry.DiscrepQty = decimal.Parse(item[TimeAndExpenseEntity.DISCREPQTY].ToString());
                    entry.DiscrpRsnCode = item[TimeAndExpenseEntity.DISCRPRSNCODE].ToString();
                    entry.Number13 = decimal.Parse(item[TimeAndExpenseEntity.NUMBER13].ToString());
                    entry.ShortChar02 = item[TimeAndExpenseEntity.SHORTCHAR02].ToString();
                    entry.Number04 = decimal.Parse(item[TimeAndExpenseEntity.NUMBER04].ToString());
                    entry.Shift = item[TimeAndExpenseEntity.SHIFT].ToString();
                    entry.PayrollDate = DateTime.Parse(item[TimeAndExpenseEntity.PAYROLLDATE].ToString());
                    entry.Status = item[TimeAndExpenseEntity.STATUS].ToString();
                    entry.SysRowId = item[TimeAndExpenseEntity.SYSROWID].ToString();
                    entry.Number20 = decimal.Parse(item[TimeAndExpenseEntity.NUMBER20].ToString());
                    entry.Number21 = decimal.Parse(item[TimeAndExpenseEntity.NUMBER21].ToString());
                    entry.Number01 = decimal.Parse(item[TimeAndExpenseEntity.NUMBER01].ToString());
                    entry.Number02 = decimal.Parse(item[TimeAndExpenseEntity.NUMBER02].ToString());
                    entry.Character01 = item[TimeAndExpenseEntity.CHARACTER01].ToString();
                    entry.ShortChar06 = item[TimeAndExpenseEntity.SHORTCHAR06].ToString();
                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
